package net.atomtree.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.atomtree.service.IndexService1;
import net.sf.json.JSONObject;

public class EngineServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String path = req.getRequestURI();
		if (path.indexOf("engine/runSpeed")!=-1){
			StringBuffer url=new StringBuffer();
			url.append("http://101.204.243.107:4040/api/v1");
			IndexService1 index=new IndexService1();
			JSONObject stageJson;
			try {
				
				stageJson = index.countSpeed(url);
				System.out.println("得到stageJson对象");
				if(null==stageJson||stageJson.equals("")){
					resp.getWriter().write(""); 
				}
				resp.getWriter().write(stageJson.toString());
				resp.setContentType("application/Json");
				resp.setCharacterEncoding("utf-8");
				resp.getWriter().flush();
				resp.getWriter().close();
			} catch (Exception e) {
				System.out.println("url解析错误或服务没有启动");
				e.printStackTrace();
			}
	}
	}
}
